package com.soulmate.gateway.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import reactor.util.annotation.NonNull;

/**
 * @author huaiping
 */
@Component
@Slf4j
public class GatewaySecurityErrorExceptionHandler implements ErrorWebExceptionHandler {
    @Override
    public Mono<Void> handle(@NonNull ServerWebExchange exchange, @NonNull Throwable ex) {
        DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(ex.getMessage().getBytes());
        return Mono.just(buffer).then();
    }
}
